"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RSATool_1 = __importDefault(require("../../lib/RSATool"));
const configTool_1 = __importDefault(require("../../com/configTool"));
function TokenAuthorityHandler() {
    return async (ctx, next) => {
        const token_get = ctx.request.query?.token;
        const token_body = ctx.request.body?.token;
        const token_header = ctx.request.header?.token;
        const token = token_get || token_body || token_header;
        await next();
        return;
        const url = decodeURI(ctx.request.url);
        if (url.includes('/AuthorizeServer/login')
            || url.startsWith('/MapResources/')
            || url.startsWith('/Resources/')
            || url.startsWith('/Web')
            || url.startsWith('/favicon.ico')
            || url.startsWith('/test/testConnect')
            || url.startsWith('/droneServer/getRtcSubscriberToken')
            || url.startsWith('/droneServer/getRtcPublisherToken')
            || url.startsWith('/DroneFile')
            || url.startsWith('/VGEEarth-SDK')
            || url.startsWith('/phone.html')
            || url === '/') {
            await next();
        }
        else if (token) {
            const ip = ctx.request.ip;
            const verify = RSATool_1.default.verifyJWT(token, ip, configTool_1.default.baseConfig.privateDer);
            if (verify) {
                await next();
            }
            else {
                ctx.status = 401;
                ctx.response.body = { code: 401, message: 'Token 错误', desc: `Token 错误` };
            }
        }
        else {
            ctx.response.status = 401;
            ctx.response.body = {
                code: 401, message: '参数缺少 Token', desc: `参数缺少 Token`
            };
        }
    };
}
exports.default = TokenAuthorityHandler;
